package com.hu.springboot.controller;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Configuration
@RequestMapping("/user")
public class LoginController {


//    @PutMapping
//    @GetMapping
//    @DeleteMapping
//    @RequestMapping(value = "/user/login",method = RequestMethod.POST)
    @PostMapping("/login")
    public String login(@RequestParam(value = "username", required = true) String username,
                        @RequestParam(value = "password", required = true) String password,
                        Map<String, Object> map, HttpSession session) {
        if (!StringUtils.isEmpty(username) && "123".equals(password)) {
            //登录成功,为了防止表单重复提交，可以重定向到主页
            session.setAttribute("loginUser", username);
            return "redirect:/main.html";
        }
        //登录失败
        map.put("msg", "用户名密码错误");
        return "login";
    }
}
